import { defHttp } from '@/utils/http';
import md5 from 'md5';

//类型
export interface LoginData {
  username: string;
  password: string;
}

enum Api {
  //用户
  Login = '/v1/system/sso',
  Logout = '/v1/system/sso',
  getCode = '/v1/system/captcha',
  GetMenu = '/v1/system/user/rule',
  GetUserInfo = '/v1/system/user/userinfo',
}

//登录
export function login(params: LoginData) {
  params = Object.assign({}, params, { password: md5(params.password) }); //加密推送
  return defHttp.post(
    { url: Api.Login, params: params },
    { errorMessageMode: 'message' }
  );
}

//退出登录
export function logout() {
  return defHttp.delete({ url: Api.Logout }, { errorMessageMode: 'message' });
}

//获取用信息
export function getUserInfo() {
  return defHttp.get({ url: Api.GetUserInfo }, { errorMessageMode: 'none' });
}

//获取验证码
export function getCode(params: object) {
  return defHttp.get(
    { url: Api.getCode, params: params },
    { errorMessageMode: 'message' }
  );
}

//获取后台菜单
export function getMenuList() {
  return defHttp.get({ url: Api.GetMenu }, { errorMessageMode: 'none' });
}
